package com.lotterymanage.web.controller;

import javax.servlet.http.HttpServletRequest;

/**
 * controller父类.
 * @author lxz
 * @date Apr 20, 2010
 */
public class BaseController {

    /**
     * 返回request中参数为param的值.
     * @param request HttpServletRequest request对象
     * @param param String 参数
     * @return value 值
     */
    protected String param(final HttpServletRequest request, final String param) {
        return request.getParameter(param);
    }

    /**
     * 返回session中参数为attr的值.
     * @param request HttpServletRequest request对象
     * @param attr String 参数
     * @return value 值
     */
    protected Object sessionGetAttr(final HttpServletRequest request, final String attr) {
        return request.getSession().getAttribute(attr);
    }

    /**
     * 向session设置参数为attr的值target.
     * @param request HttpServletRequest request对象
     * @param attr String 参数
     * @param target Object 值
     */
    protected void sessionSetAttr(final HttpServletRequest request, final String attr, final Object target) {
        request.getSession().setAttribute(attr, target);
    }

    /**
     * 返回当前项目的contextPath.
     * @param request HttpServletRequest
     * @return contextPath
     */
    protected String contextPath(final HttpServletRequest request) {
        return request.getContextPath();
    }
}
